const publicStyle = { style: { width: "240px" } }
export const formOption = ref({
  inline: true,
  showResetButton: true,
})
export const fieldList = ref([
  {
    field: "shopCascade",
    slot: "ShopCascade",
  },
  {
    field: "skuRange",
    placeholder: "可批量搜索",
    type: "textarea",
    ...publicStyle,
    select: [
      { label: "sku", value: "sku" },
      { label: "自定义sku", value: "custom_sku" },
      { label: "渠道sku", value: "platform_sku" },
      { label: "spu", value: "spu" },
      { label: "ASIN", value: "asin" },
      { label: "商品中文名", value: "sku_cn_title" },
    ],
  },
  {
    field: "noRange",
    placeholder: "可批量搜索",
    type: "textarea",
    ...publicStyle,
    selectStyle: { width: "120px" },
    select: [
      { label: "系统订单号", value: "order_sn" },
      { label: "平台订单号", value: "platform_order_sn" },
      { label: "买家姓名", value: "buyer_name" },
    ],
  },
  {
    field: "create_user",
    type: "cascader",
    selectStyle: { width: "120px" },
    itemProps: { placeholder: "可批量搜索" },
    select: [
      { label: "退款操作人", value: "create_user" },
      { label: "客服人员", value: "customer_service_id" },
      { label: "运营人员", value: "sales_id" },
      { label: "审核人员", value: "reviewer_id" },
    ],
  },
  {
    field: "timeRange",
    type: "dateTimeRangeNorm",
    select: [
      { label: "申请时间", value: "apply_at" },
      { label: "审核时间", value: "review_at" },
      { label: "API退款时间", value: "api_refund_at" },
      { label: "支付时间", value: "pay_time" },
      { label: "发货时间", value: "shipping_time" },
    ],
    selectStyle: { width: "120px" },
  },

  { slot: "reason" },
  {
    field: "refund_amount",
    type: "numberRange",
    prepend: "退款金额",
    ...publicStyle,
    // suffix: "RMB",
  },

  {
    field: "order_currency",
    type: "select",
    originField: "countryOpt",
    options: { placeholder: "币种" },
    style: { width: "100px" },
  },

  {
    field: "shipping_type",
    type: "select",
    options: {
      placeholder: "订单发货类型",
    },
    origin: "shipping_type",
    style: { width: "140px" },
  },
  {
    field: "refund_status",
    type: "select",
    options: {
      placeholder: "退款状态",
    },
    origin: "refund_status",
    style: { width: "140px" },
  },
  {
    field: "is_dispute",
    type: "select",
    options: {
      placeholder: "是否存在纠纷",
      data: [
        { label: "不存在", value: 0 },
        { label: "存在", value: 1 },
      ],
    },
    style: { width: "140px" },
  },
  {
    field: "dispute_type",
    type: "select",
    options: {
      placeholder: "纠纷类型",
    },
    origin: "refund_dispute_type",
    style: { width: "140px" },
  },
  {
    field: "cargo_handler",
    type: "select",
    options: {
      placeholder: "货物处理",
    },
    origin: "cargo_handler",
    style: { width: "140px" },
  },
  {
    field: "refund_type",
    type: "select",
    options: {
      placeholder: "退款类型",
    },
    origin: "refund_type",
    style: { width: "140px" },
  },
  {
    field: "shipping_status",
    type: "select",
    options: {
      placeholder: "发货状态",
    },
    origin: "shipping_status",
    style: { width: "140px" },
  },
  {
    field: "is_api_refund",
    type: "select",
    options: {
      placeholder: "是否API退款",
    },
    origin: "refund_api_action",
    style: { width: "140px" },
  },
  {
    field: "api_refund_status",
    type: "select",
    options: {
      placeholder: "API退款状态",
    },
    origin: "refund_api_status",
    style: { width: "140px" },
  },
  {
    field: "ascription_extend",
    // label: "ebay订单站点",
    type: "select",
    origin: "ebay_site",
    multiple: true,
    collapseTags: true,
    options: { placeholder: "ebay订单站点" },
    style: { width: "160px" },
  },
  {
    field: "recipient_country_id",
    slot: "RecipientCountry",
    options: { placeholder: "收件国家" },
  },
])

const remarkConfig = [
  { label: "退款描述", field: "customer_refund_description" },
  { label: "备注", field: "refund_remark" },
]

const cargoConfig = [
  { label: "处理方式：", field: "cargo_handler_desc" },
  { label: "退件单号：", field: "exchange_sn" },
  { label: "退件仓库：", field: "return_warehouse" },
  { label: "退件追踪号：", field: "tracking_number" },
]

const personnelConfig = [
  { label: "客服：", field: "customer_service" },
  { label: "建单：", field: "refund_operator" },
  { label: "审批：", field: "approve_operator" },
]

const timeConfig = [
  { label: "支付：", field: "pay_time" },
  { label: "创建：", field: "create_time" },
  { label: "审批：", field: "review_at" },
  { label: "API：", field: "api_refund_at" },
]

// 操作
export const handleFunctions = ref({})

export const tablecColumns = ref([
  {
    params: "left",
    width: 260,
    title: "订单信息",
    field: "a2",
    slots: {
      default: ({ row }) => {
        return (
          <div>
            <VText title="退款ID" value={row.id} line={1} />
            <VText title="平台/站点" value={`${row.platform}${row.site && "/" + row.site}`} line={1} />
            <VText title="店铺" value={row.shop} line={1} />
            <VText title="系统" value={row.order_sn} line={1} type="link" onClick={() => handleFunctions?.value?.handleDetail(row.order_sn)} />
            <VText title="平台订单号" value={row.platform_order_sn} line={1} type="link" />
            <VText title="发货类型" value={row.shipping_type_desc} line={1} />
            {/* ebay 订单 */}
            {row.platform_id == 1 ? <VText title="买家姓名" value={row.buyer_name} line={1} class="text-green" /> : ""}
          </div>
        )
      },
    },
  },
  {
    title: "商品信息",
    width: 400,
    slots: {
      default: "GoodsSlot",
    },
  },
  {
    title: "退款状态",
    width: 200,
    slots: {
      default: ({ row }) => {
        return (
          <div>
            <p class="text-[16px] font-[600] text-[var(--base-text-color)] mb-[4px]">{row.refund_status_desc}</p>
            <VText title="存在纠纷" value={row?.is_dispute_desc} line={1} />
            {row.is_dispute == 1 && row.is_cut_payment == 1 ? <VText title="是否扣款" value={row?.is_cut_payment_desc} line={1} /> : ""}

            {row.platform_id == 1 ? (
              <div>
                <VText title="API退款状态" value={row?.is_api_refund_desc} line={1} />
                <VText title="API退款状态" value={row?.api_refund_status_desc} line={1} />
              </div>
            ) : (
              ""
            )}
          </div>
        )
      },
    },
  },
  {
    title: "退款金额",
    width: 200,
    slots: {
      default: ({ row }) => {
        return (
          <div class="text-[14px] text-[#3a4259] leading-[22px] label">
            <p class="text-[16px] value">{row.refund_type_desc}</p>
            <p>
              退款金额(不含税)
              <span class="text-[#FF0000] ml-[4px]">
                {row.order_currency} {row.refund_amount}
              </span>
            </p>
            <p>
              退款金额(含税)
              <span class="text-[#FF0000] ml-[4px]">
                {row.order_currency} {row.refund_amount_tax}
              </span>
            </p>
            <p>
              订单金额(含税)
              <span class="ml-[4px] value">
                {row.order_currency} {row.original_order_amount || "-"}
              </span>
            </p>
          </div>
        )
      },
    },
  },
  {
    title: "退款原因",
    width: 200,
    slots: {
      default: ({ row }) => {
        return (
          <div class="text-[14px] text-[#3a4259] leading-[22px]">
            <p>{row.dispute_type_desc}</p>
            <p>
              {row.primary_cause}
              {row.secondary_cause ? `${row.primary_cause ? "/" : ""} ${row.secondary_cause}` : ""}
            </p>
          </div>
        )
      },
    },
  },
  {
    title: "备注原因",
    width: 200,
    slots: {
      default: ({ row }) => {
        return (
          <div>
            {remarkConfig.map((n) => (
              <VText title={n.label} value={row[n.field]} line={99} />
            ))}
          </div>
        )
      },
    },
  },
  {
    title: "货物处理",
    width: 200,
    slots: {
      default: ({ row }) => {
        return (
          <div>
            {cargoConfig.map((n) => (
              <VText title={n.label} value={row[n.field]} line={1} />
            ))}
          </div>
        )
      },
    },
  },
  {
    title: "操作人",
    width: 200,
    slots: {
      default: ({ row }) => {
        return (
          <div>
            {row["sales"] && row["sales"].map((n) => <VText title={n.label} value={row[n.field]} line={1} />)}
            {personnelConfig.map((n) => (
              <VText title={n.label} value={row[n.field]} line={1} />
            ))}
          </div>
        )
      },
    },
  },
  {
    title: "时间",
    width: 230,
    slots: {
      default: ({ row }) => {
        return (
          <div>
            {timeConfig.map((n) => (
              <VText title={n.label} value={row[n.field]} line={1} />
            ))}
          </div>
        )
      },
    },
  },
])
